#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int maximumUniqueSubarray(vector<int>& nums) {
        unordered_map<int, bool> hash;
        int left = 0;
        int sum = 0, res = 0;
        for (int right = 0; right < nums.size(); right++)
        {
            int m = nums[right];
            sum += m;
            while (hash[m] == true)
            {
                int k = nums[left++];
                sum -= k;
                hash[k] = false;
            }
            hash[m] = true;
            res = max(res, sum);
        }
        return res;
    }
};